//
//  DSTabBarController.m
//  项目A_百思不得姐
//
//  Created by wudongyang on 16/5/15.
//  Copyright © 2016年 wudongyang. All rights reserved.
//

#import "DSTabBarController.h"
// 精华页
#import "EssenceViewController.h"
// 最新页
#import "NewViewController.h"
// 关注页(我的订阅)
#import "SubscribeViewController.h"
// 我的页
#import "MeViewController.h"
// 红色加号页
#import "RedAddViewController.h"
// 引入自定义TabBar头文件
#import "DSTabBar.h"
// 引入自定义的NavigationController头文件
#import "DSNavigationController.h"

#import "RedAddViewController.h"
@interface DSTabBarController ()

@end

@implementation DSTabBarController

+(void)initialize{
    // 未选中状态下文字大小和颜色(未选中:uncheck)
    NSMutableDictionary *uncheck = [NSMutableDictionary dictionary];
    uncheck[NSFontAttributeName] = [UIFont systemFontOfSize:12];
    uncheck[NSForegroundColorAttributeName] = [UIColor grayColor];
    // 选中状态下文字大小和颜色(选中:selected)
    NSMutableDictionary *selected = [NSMutableDictionary dictionary];
    selected[NSFontAttributeName] = uncheck[NSFontAttributeName];
    selected[NSForegroundColorAttributeName] = [UIColor darkGrayColor];
    // 通过appearance统一设置所有UITabBarItem的文字属性
    // 后面带有UI_APPEARANCE_SELECTOR的方法,都可以通过appearance对象统一设置
    UITabBarItem *item = [UITabBarItem appearance];
    [item setTitleTextAttributes:uncheck forState:UIControlStateNormal];
    [item setTitleTextAttributes:selected forState:UIControlStateSelected];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 添加子控制器一(精华)
    [self setupChildVc:[[EssenceViewController alloc] init] title:@"精华" image:@"tabBar_essence_icon" selectedImage:@"tabBar_essence_click_icon"];
    
    // 添加子控制器二(最新)
    [self setupChildVc:[[NewViewController alloc] init] title:@"最新" image:@"tabBar_new_icon" selectedImage:@"tabBar_new_click_icon"];
    
    // 添加子控制器三(关注)
    [self setupChildVc:[[SubscribeViewController alloc] init] title:@"关注" image:@"tabBar_friendTrends_icon" selectedImage:@"tabBar_friendTrends_click_icon"];
    
    // 添加子控制器四(我)
    [self setupChildVc:[[MeViewController alloc] init] title:@"我" image:@"tabBar_me_icon" selectedImage:@"tabBar_me_click_icon"];
    
    // 更换tabBar
    DSTabBar *mytabBar = [[DSTabBar alloc]init];
    [self setValue:mytabBar forKey:@"TabBar"];
    
    mytabBar.RedAddBlock = ^(UIButton *button){
    
            RedAddViewController *redaddVC = [[RedAddViewController alloc] init];
        [self presentViewController:redaddVC animated:YES completion:nil];
    };
    
    
    
}
// 初始化子控制器(参数1:Controller 参数2:文字 参数3:未选中图片 参数4:被选中图片)
-(void)setupChildVc:(UIViewController *)vc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage{
    // 设置文字和图片
    vc.navigationItem.title = title;
    vc.tabBarItem.title = title;
    vc.tabBarItem.image = [UIImage imageNamed:image];
    vc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];

    // 包装一个导航控制器,添加导航控制器为tabBarController的子控制器
    DSNavigationController *naVC = [[DSNavigationController alloc] initWithRootViewController:vc];
    
    [self addChildViewController:naVC];
    
    


}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
